package com.mtsmda.jpa.run;

import javax.persistence.EntityManager;
import javax.persistence.Persistence;

import com.mtsmda.jpa.domain.manytomanyBidirectional.ClassRoom;
import com.mtsmda.jpa.domain.manytomanyBidirectional.Teacher;

public class ManyToManyBiDirectionalServiceRun {

	public static void main(String[] args) {
		EntityManager entityManager = Persistence.createEntityManagerFactory(
				"MTSMDA").createEntityManager();
		entityManager.getTransaction().begin();

		ClassRoom classRoom = new ClassRoom("Story", 159);
		
		Teacher teacher = new Teacher("Ivan", "Panteleevici");
		Teacher teacher1 = new Teacher("Egor", "Petrovici");
		
		classRoom.getTeachers().add(teacher);
		classRoom.getTeachers().add(teacher1);
		
		teacher.getClassRooms().add(classRoom);
		teacher1.getClassRooms().add(classRoom);
		
		entityManager.persist(classRoom);
		

		entityManager.getTransaction().commit();
		entityManager.close();
	}

}